//package com.trafficsys.modules.loginAndRegister.controller;
//
//import com.trafficsys.modules.entity.*;
//import com.trafficsys.modules.loginAndRegister.config.ResourceConfigBean;
//import com.trafficsys.modules.loginAndRegister.service.LoginAndRegisterService;
//import com.trafficsys.modules.loginAndRegister.util.FindAllFile;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//import org.springframework.web.servlet.mvc.support.RedirectAttributes;
//
//import java.io.File;
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.List;
//
///**
// * @Author Zhao Bin
// * @Date 2021/9/27 8:56
// * @Version 1.0
// */
//@Controller
//@RequestMapping("/api")
//public class LoginAndRegisterController {
//    @Autowired
//    private LoginAndRegisterService lrService;
//    @Autowired
//    private ResourceConfigBean resourceConfigBean;
//
//    /*********************************************   以下驾驶员功能  *********************************************************
//     * 驾驶员登录（身份证、手机号码结合密码登录）    驾驶员功能
//     *  posy:
//     *  http://localhost:8080/api/driverLogin?&phone=15730593398&password=15730593398
//     *  json:
//     *  http://localhost:8080/api/driverLogin
//     *  {
//     *     "cardId":"500235199805059270",
//     *     "password":"15730593398"
//     *  }
//     */
//    @PostMapping(value = "/driverLogin", consumes = "application/json")
//    @ResponseBody//将数据返回到body展示
//    public HashMap<String,Object> driverLogin(@RequestBody Driver driver){return lrService.driverLogin(driver); }
//    /**
//     *  驾驶员注册   驾驶员功能
//     *  post:
//     *  http://localhost:8080/api/register?cardId=500235199805059270&name=赵彬&phone=15730593398&password=15730593398
//     *  json:
//     *  http://localhost:8080/api/register
//     *  {
//     *     "cardId":"500235199850509270",
//     *     "name":"赵彬",
//     *     "password":"15730593398",
//     *     "phone":"15730593398"
//     * }
//     */
//    @PostMapping(value = "/register", consumes = "application/json")
//    @ResponseBody
//    public HashMap<String,Object> register(@RequestBody Driver driver){
//        return lrService.register(driver);
//    }
//    /**
//     *  驾驶员查看驾驶证信息  驾驶员功能
//     *  json:
//     *  http://localhost:8080/api/showDriveCard
//     *  {"cardId":"500235199805059270"}
//     */
//    @PostMapping(value = "/showDriveCard", consumes = "application/json")
//    @ResponseBody
//    public HashMap<String,Object> showDriveCard(@RequestBody Driver driver){ return lrService.showDriveCard(driver);}
//    /**
//     *  驾驶员查看行驶证信息  驾驶员功能
//     *  http://localhost:8080/api/showTravelCard
//     *  {"cardId":"500235199805059270"}
//     */
//    @PostMapping(value = "/showTravelCard",consumes = "application/json")
//    @ResponseBody
//    public HashMap<String,Object> showTravelCard(@RequestBody Driver driver){return lrService.showTravelCard(driver);}
//
//
//
//    /*********************************************   以下管理员功能  *********************************************************
//     * 警员员登录    管理员功能
//     * post:
//     * http://localhost:8080/api/policeLogin?&phone=15730593398&password=15730593398
//     * json:
//     * http://localhost:8080/api/policeLogin
//     * {
//     *     "cardId":"500235199805059270",
//     *     "password":"15730593398"
//     * }
//     */
//    @PostMapping(value = "/policeLogin", consumes = "application/json")
//    @ResponseBody
//    public HashMap<String,Object> policeLogin(@RequestBody Police police){return lrService.policeLogin(police); }
//
//    /**
//     * 添加驾驶证方法   管理员功能
//     * post:
//     * http://localhost:8080/api/addDriveCard?driveCardId=500235199805059270&cardId=500235199805059270&nationality=中国&clazz=C1&department=成都交警总队&score=12&state=在用
//     * json:
//       {
//          "driveCardId":"500235199805059270A1",
//          "cardId":"500235199805059270",
//          "nationality":"中国",
//          "clazz":"A1",
//          "department":"成都交警总队",
//          "score":"12",
//          "state":"在用"
//      }
//     */
//    @PostMapping(value = "/addDriveCard", consumes = "application/json")
//    @ResponseBody
//    public HashMap<String,Object> addDriveCard(@RequestBody DriveCard driveCard){
//        return lrService.addDriveCard(driveCard);
//    }
//    /**
//     * 添加行驶证方法   管理员功能
//     * http://localhost:8080/api/addTravelCard?travelCarId=500235199805059270渝A9999&carNo=渝A 99999&carClazz=大型SUV&cardId=500235199805059270&userNature=民用&brandModel=保时捷Utrl&vin=45347542355236&engineNo=6754345&fileNo=3442332&state=在用
//     {
//     "travelCarId":"500235199805059270渝A11111",
//     "carNo":"渝A 11111",
//     "carClazz":"大型SUV",
//     "cardId":"500235199805059270",
//     "userNature":"民用",
//     "brandModel":"保时捷Utrl",
//     "vin":"45347542355236",
//     "engineNo":"6754345",
//     "fileNo":"3442332",
//     "state":"在用"
//     }
//     */
//    @PostMapping(value = "/addTravelCard", consumes = "application/json")
//    @ResponseBody
//    //添加行驶证方法   管理员功能
//    public HashMap<String, Object> addTravelCard(@RequestBody TravelCard travelCard){
//        return lrService.addTravelCard(travelCard);
//    };
//    /**
//     * 添加警员    管理员功能
//     * post:
//     * http://localhost:8080/api/addPolice?cardId=500235199805059270&name=赵彬&phone=15730593398&password=15730593398
//     * json:
//     {
//        "cardId":"500235199805059271",
//        "name":"赵彬",
//        "phone":"15730593398",
//        "password":"15730593398"
//     }
//     */
//    @PostMapping(value = "/addPolice", consumes = "application/json")
//    @ResponseBody
//    public HashMap<String,Object> addPolice(@RequestBody Police police){
//        return lrService.addPolice(police);
//    }
//
//
//
//    /*********************************************   以下公用功能  *********************************************************
//     *  添加身份证信息    公用功能
//     *  post:
//     *  http://localhost:8080/api/addIdCard?cardId=500235199805059270&name=赵彬&birthday=1998-05-05&address=中国重庆云阳&department=重庆市公安局&state=在用
//     {
//        "cardId":"500235199805059271",
//        "name":"赵彬",
//        "birthday":"1998-05-05",
//        "address":"中国重庆云阳",
//        "department":"重庆市公安局",
//        "state":"在用"
//     }
//     */
//    @PostMapping(value = "/addIdCard", consumes = "application/json")
//    @ResponseBody//将数据返回到body展示
//    public HashMap<String,Object> addIdCard(@RequestBody IdCard idCard){return lrService.addIdCard(idCard); }
//    /**
//     * 发送手机验证码   公用功能
//     *  post:
//     *  http://localhost:8080/api/sendMessage?phone=15730593398
//     */
//    @PostMapping(value = "/sendMessage", consumes = "application/json")
//    @ResponseBody//将数据返回到body展示
//    public HashMap<String,Object> sendMessage(String phone){
//        return lrService.sendMessage(phone);
//    }
//    /**
//     * 上传文件   公用功能
//     */
//    @PostMapping(value = "/uploadFile", consumes = "multipart/form-data")
//    @ResponseBody
//    public HashMap<String,Object> uploadFile(@RequestBody MultipartFile file, String cardId) {
//        HashMap<String,Object> map=new HashMap<>();
//        if(file == null){
//            map.put("info","您还没有选择文件！");
//            return map;
//        }
//        //检查是否有对应用户的文件夹 没有则创建一个
//        String path=String.format("%s%s", resourceConfigBean.getLocalPathForWindow(), cardId);
//        File uploadFile=new File(path);
//        if(!uploadFile.exists()){
//            //创建文件夹
//            uploadFile.mkdir();
//        }
//        //获取本地文件目录中的所有文件
//        FindAllFile findAllFile = new FindAllFile();
//        List<String> hadFileNames = findAllFile.findAllFile(path);
//        for (String one : hadFileNames) {
//            if (one.equals(file.getOriginalFilename())) {
//                map.put("info",file.getOriginalFilename() + "文件已存在\n");
//                return map;
//            }
//        }
//        try {
//            String destFilePath = String.format("%s%s%s",
//                    resourceConfigBean.getLocalPathForWindow(), cardId+"/",file.getOriginalFilename());
//            File destFile = new File(destFilePath);
//            file.transferTo(destFile);
//            map.put("info",file.getOriginalFilename() + "文件上传成功");
//            return map;
//        } catch (IOException e) {
//            e.printStackTrace();
//            map.put("info",e.getMessage());
//            return map;
//        }
//    }
//}
